#!/usr/bin/env sh

. ${HOME}/.config/scripts/color/i3blocks-usage-color.sh

getTctl() {
  DIR=/sys/class/hwmon
  ls ${DIR}/hwmon*/temp*_label | while read -r label; do
    if [ "$(cat ${label})" == "Tctl" ]; then
      cat $(echo "${label}" | sed 's/label$/input/')
      break
    fi
  done
}

ICON="\Uef2b"
TEMPERATURE=$(echo "scale=1; $(getTctl)/1000" | bc )

if [ $(echo "${TEMPERATURE} < 40" | bc) -eq 1 ] ; then
    ICON_COLOR=${VERY_LOW_USAGE_COLOR}
elif [ $(echo "${TEMPERATURE} < 60" | bc) -eq 1 ] ; then
    ICON_COLOR=${LOW_USAGE_COLOR}
elif [ $(echo "${TEMPERATURE}<80" | bc) -eq 1 ] ; then
    ICON_COLOR=${MIDDLE_USAGE_COLOR}
else
    ICON_COLOR=${HIGH_USAGE_COLOR}
fi

echo -e "${ICON} ${TEMPERATURE}\Uf0504\n\n${ICON_COLOR}"
